package com.ruoyi.energy.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.TcStatistics;
import com.ruoyi.energy.domain.vo.TcStatisticsWXVO;
import com.ruoyi.energy.service.ITcStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 停车场统计Controller
 *
 * @author cjie
 * @date 2022-04-25
 */
@Api(tags = " 停车场统计")
@RestController
@RequestMapping("/tcStatistics")
public class TcStatisticsController extends BaseController {
    @Autowired
    private ITcStatisticsService tcStatisticsService;

    /**
     * 查询停车场统计列表
     */
    @ApiOperation(value="查询停车场统计列表", notes="查询停车场统计列表")
    @PreAuthorize(hasPermi = "energy:tcStatistics:list")
    @GetMapping("/list")
    public TableDataInfo list(TcStatistics tcStatistics) {
        startPage();
        List<TcStatistics> list = tcStatisticsService.selectTcStatisticsList(tcStatistics);
        return getDataTable(list);
    }

    /**
     * 微信统计列表
     */
    @ApiOperation(value="微信统计收费", notes="微信统计收费")
    @PreAuthorize(hasPermi = "energy:tcStatistics:list")
    @GetMapping("/wx/list")
    public AjaxResult wxList(TcStatisticsWXVO wxvo) {
        TcStatisticsWXVO list = tcStatisticsService.selectTcStatisticsWXVO(wxvo);
        return AjaxResult.success(list);
    }

    /**
     * 导出停车场统计列表
     */
    @ApiOperation(value="导出停车场统计列表", notes="导出停车场统计列表")
    @PreAuthorize(hasPermi = "energy:tcStatistics:export")
    @Log(title = "停车场统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcStatistics tcStatistics) throws IOException {
        List<TcStatistics> list = tcStatisticsService.selectTcStatisticsList(tcStatistics);
        ExcelUtil<TcStatistics> util = new ExcelUtil<TcStatistics>(TcStatistics.class);
        util.exportExcel(response, list, "停车场统计数据");
    }
    /**
     * 获取停车场统计详细信息
     */
    @ApiOperation(value="获取停车场统计详细信息", notes="获取停车场统计详细信息")
    @PreAuthorize(hasPermi = "energy:tcStatistics:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tcStatisticsService.selectTcStatisticsById(id));
    }

    @ApiOperation(value="按日期生成停车费统计", notes="按日期生成停车费统计")
    @GetMapping(value = "/genStaticByDate/{staticDate}")
    public R genStaticByDate(@PathVariable("staticDate") String staticDate) {
        return toR(tcStatisticsService.genStaticByDate(staticDate));
    }

    /**
     * 新增停车场统计
     */
    @ApiOperation(value="新增停车场统计", notes="新增停车场统计")
    @PreAuthorize(hasPermi = "energy:tcStatistics:add")
    @Log(title = "停车场统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcStatistics tcStatistics) {
        return toAjax(tcStatisticsService.insertTcStatistics(tcStatistics));
    }

    /**
     * 修改停车场统计
     */
    @ApiOperation(value="修改停车场统计", notes="修改停车场统计")
    @PreAuthorize(hasPermi = "energy:tcStatistics:edit")
    @Log(title = "停车场统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcStatistics tcStatistics) {
        return toAjax(tcStatisticsService.updateTcStatistics(tcStatistics));
    }

    /**
     * 删除停车场统计
     */
    @ApiOperation(value="删除停车场统计", notes="删除停车场统计")
    @ApiImplicitParam(name = "ids", value = "停车场统计ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:tcStatistics:remove")
    @Log(title = "停车场统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tcStatisticsService.deleteTcStatisticsByIds(ids));
    }
}
